package com.hxgis.common.service.impl;

import com.es.common.EsAggCondition;
import com.es.common.domain.EsCondition;
import com.es.common.domain.agg.Group;
import com.es.wrapper.DataWrapper;
import com.hxgis.common.base.StationCache;
import com.hxgis.common.dto.RainInfoAnalysDTO;
import com.hxgis.common.entity.RainDayInfo;
import com.hxgis.common.entity.Station;
import com.hxgis.common.repository.RainDayInfoRepository;
import com.hxgis.common.repository.StationInfoRepository;
import com.hxgis.common.repository.cimiss.SurfChnMulDayMapper;
import com.hxgis.common.service.RainDayService;
import com.hxgis.common.utils.RectField;
import com.hxgis.common.utils.TimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;


@Service
@Slf4j
public class RainDayServiceImpl implements RainDayService {



    @Autowired
    StationInfoRepository stationInfoRepository;

    @Autowired
    private RainDayInfoRepository rainDayInfoRepository;

    @Autowired
    private SurfChnMulDayMapper surfChnMulDayMapper;




    @Override
    public void addToRainEs(String startTime, String endTime, List<String> sids) {
//        String dataFormat = "json";
        /* 2.3  接口参数，多个参数间无顺序 */
//        HashMap<String, String> params = new HashMap<String, String>();
        //必选参数
        //必选参数
//        params.put("dataCode", "SURF_CHN_MUL_DAY"); //资料代码，中国地面逐小时资料
//        params.put("elements", "Station_Id_C,PRE_Time_2020,PRE_Time_0808,Datetime"); //统计分组要素：站号，站名
//        params.put("times", day);  //统计时间段，时间范围，前开后闭  时间个数最多只能是20个
//        params.put("times", day);  //统计时间段，时间范围，前开后闭  时间个数最多只能是20个
        List<RainDayInfo> rainDayInfos = deviceToRainDay(startTime, endTime ,sids);
        rainDayInfoRepository.saveBatchNotNull(rainDayInfos);
    }



    /**
     * 补全多日降水极值排位信息 08
     * @param startTime
     * @param endTime
     * @param stations
     */
    @Override
    public void completionRainDay08(String startTime, String endTime, List<String> stations) {
        //直接一口气查这批数据
        String pre14TimeInit = TimeUtil.preDay(startTime,14);

        //查询这段时间的数据，避免频繁查询es 查询出来的数据可以进行代码操作

        //这里可以不用处理不正确的数据 后面查询的时候处理
        EsCondition time = EsCondition.getEsCondition()
                .gte("time", pre14TimeInit).lte(endTime)
                .LTE("rainFall08",20000)
                .in("stationNo",stations)
                .size(1000000);
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(time);
        //list转 stationmap
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));

        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(startTime,1), TimeUtil.nextDay(endTime,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        List<RainDayInfo> rainDayInfoList = new ArrayList<>();
        //循环所有的站点一个个的计算
        for (String stationNo : stations) {
            if (org.springframework.util.CollectionUtils.isEmpty(stationMap.get(stationNo))){
                continue;
            }
            //循环所有的时间日期
            for (String nowTime : monthBetweenDateStr) {
                //查询当前站点的时间段降水信息
                List<RainDayInfo> rainDayInfos1 = stationMap.get(stationNo);
                Collections.sort(rainDayInfos1,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                Map<Long, List<RainDayInfo>> timeMap = rainDayInfos1.stream().collect(Collectors.groupingBy(RainDayInfo::getTime));
                RainDayInfo rainDayInfo = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(nowTime))) ? null : timeMap.get(Long.valueOf(nowTime)).get(0);
                //因为当前时间的降雨量可能是错误的数据过滤调了，这里都不用计算了，直接跳出当前循环
                if (Objects.isNull(rainDayInfo)){
                    continue;
                }
//                log.info("当前计算08极值多日数据{}",nowTime);
                String pre14Time = TimeUtil.preDay(nowTime,14);
                String pre13Time = TimeUtil.preDay(nowTime,13);
                String pre12Time = TimeUtil.preDay(nowTime,12);
                String pre11Time = TimeUtil.preDay(nowTime,11);
                String pre10Time = TimeUtil.preDay(nowTime,10);
                String pre09Time = TimeUtil.preDay(nowTime,9);
                String pre08Time = TimeUtil.preDay(nowTime,8);
                String pre07Time = TimeUtil.preDay(nowTime,7);
                String pre06Time = TimeUtil.preDay(nowTime,6);
                String pre05Time = TimeUtil.preDay(nowTime,5);
                String pre04Time = TimeUtil.preDay(nowTime,4);
                String pre03Time = TimeUtil.preDay(nowTime,3);
                String pre02Time = TimeUtil.preDay(nowTime,2);
                String pre01Time = TimeUtil.preDay(nowTime,1);

                Integer rainFall0801 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre01Time))) ? 0 : timeMap.get(Long.valueOf(pre01Time)).get(0).getRainFall08();
                Integer rainFall0802 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre02Time))) ? 0 : timeMap.get(Long.valueOf(pre02Time)).get(0).getRainFall08();
                Integer rainFall0803 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre03Time))) ? 0 : timeMap.get(Long.valueOf(pre03Time)).get(0).getRainFall08();
                Integer rainFall0804 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre04Time))) ? 0 : timeMap.get(Long.valueOf(pre04Time)).get(0).getRainFall08();
                Integer rainFall0805 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre05Time))) ? 0 : timeMap.get(Long.valueOf(pre05Time)).get(0).getRainFall08();
                Integer rainFall0806 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre06Time))) ? 0 : timeMap.get(Long.valueOf(pre06Time)).get(0).getRainFall08();
                Integer rainFall0807 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre07Time))) ? 0 : timeMap.get(Long.valueOf(pre07Time)).get(0).getRainFall08();
                Integer rainFall0808 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre08Time))) ? 0 : timeMap.get(Long.valueOf(pre08Time)).get(0).getRainFall08();
                Integer rainFall0809 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre09Time))) ? 0 : timeMap.get(Long.valueOf(pre09Time)).get(0).getRainFall08();
                Integer rainFall0810 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre10Time))) ? 0 : timeMap.get(Long.valueOf(pre10Time)).get(0).getRainFall08();
                Integer rainFall0811 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre11Time))) ? 0 : timeMap.get(Long.valueOf(pre11Time)).get(0).getRainFall08();
                Integer rainFall0812 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre12Time))) ? 0 : timeMap.get(Long.valueOf(pre12Time)).get(0).getRainFall08();
                Integer rainFall0813 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre13Time))) ? 0 : timeMap.get(Long.valueOf(pre13Time)).get(0).getRainFall08();
                Integer rainFall0814 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre14Time))) ? 0 : timeMap.get(Long.valueOf(pre14Time)).get(0).getRainFall08();
                //处理08时的数据
                rainDayInfo.setRainFall08_2(rainFall0801 + rainDayInfo.getRainFall08());
                rainDayInfo.setRainFall08_3(rainDayInfo.getRainFall08_2() + rainFall0802);
                rainDayInfo.setRainFall08_4(rainDayInfo.getRainFall08_3() + rainFall0803);
                rainDayInfo.setRainFall08_5(rainDayInfo.getRainFall08_4() + rainFall0804);
                rainDayInfo.setRainFall08_6(rainDayInfo.getRainFall08_5() + rainFall0805);
                rainDayInfo.setRainFall08_7(rainDayInfo.getRainFall08_6() + rainFall0806);
                rainDayInfo.setRainFall08_8(rainDayInfo.getRainFall08_7() + rainFall0807);
                rainDayInfo.setRainFall08_9(rainDayInfo.getRainFall08_8() + rainFall0808);
                rainDayInfo.setRainFall08_10(rainDayInfo.getRainFall08_9() + rainFall0809);
                rainDayInfo.setRainFall08_11(rainDayInfo.getRainFall08_10() + rainFall0810);
                rainDayInfo.setRainFall08_12(rainDayInfo.getRainFall08_11() + rainFall0811);
                rainDayInfo.setRainFall08_13(rainDayInfo.getRainFall08_12() + rainFall0812);
                rainDayInfo.setRainFall08_14(rainDayInfo.getRainFall08_13() + rainFall0813);
                rainDayInfo.setRainFall08_15(rainDayInfo.getRainFall08_14() + rainFall0814);
                rainDayInfoList.add(rainDayInfo);
            }
        }
        log.info("当前计算得是{}到{}，的08时多日降水，保存到降水基础信息表",startTime,endTime);
        rainDayInfoRepository.saveBatch(rainDayInfoList);
    }


    /**
     * 补全多日降水极值排位信息
     * @param startTime
     * @param endTime
     * @param stations
     */
    @Override
    public void completionRainDay20(String startTime, String endTime, List<String> stations) {
        //直接一口气查这批数据
        String pre14TimeInit = TimeUtil.preDay(startTime,14);

        //查询这段时间的数据，避免频繁查询es 查询出来的数据可以进行代码操作

        //这里可以不用处理不正确的数据 后面查询的时候处理
        EsCondition time = EsCondition.getEsCondition().gte("time", pre14TimeInit).lte(endTime)
                .LTE("rainFall",20000)
                .in("stationNo",stations)
                .size(1000000);
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(time);
        //list转 stationmap
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));

        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(startTime,1), TimeUtil.nextDay(endTime,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        List<RainDayInfo> rainDayInfoList = new ArrayList<>();
        //循环所有的站点一个个的计算
        for (String stationNo : stations) {
            if (org.springframework.util.CollectionUtils.isEmpty(stationMap.get(stationNo))){
                continue;
            }
            //循环所有的时间日期
            for (String nowTime : monthBetweenDateStr) {
                //查询当前站点的时间段降水信息
                List<RainDayInfo> rainDayInfos1 = stationMap.get(stationNo);
                Collections.sort(rainDayInfos1,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                Map<Long, List<RainDayInfo>> timeMap = rainDayInfos1.stream().collect(Collectors.groupingBy(RainDayInfo::getTime));
                RainDayInfo rainDayInfo = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(nowTime))) ? null : timeMap.get(Long.valueOf(nowTime)).get(0);
                //因为当前时间的降雨量可能是错误的数据过滤调了，这里都不用计算了，直接跳出当前循环
                if (Objects.isNull(rainDayInfo)){
                    continue;
                }
//                log.info("当前计算20极值多日数据{}",nowTime);
                String pre14Time = TimeUtil.preDay(nowTime,14);
                String pre13Time = TimeUtil.preDay(nowTime,13);
                String pre12Time = TimeUtil.preDay(nowTime,12);
                String pre11Time = TimeUtil.preDay(nowTime,11);
                String pre10Time = TimeUtil.preDay(nowTime,10);
                String pre09Time = TimeUtil.preDay(nowTime,9);
                String pre08Time = TimeUtil.preDay(nowTime,8);
                String pre07Time = TimeUtil.preDay(nowTime,7);
                String pre06Time = TimeUtil.preDay(nowTime,6);
                String pre05Time = TimeUtil.preDay(nowTime,5);
                String pre04Time = TimeUtil.preDay(nowTime,4);
                String pre03Time = TimeUtil.preDay(nowTime,3);
                String pre02Time = TimeUtil.preDay(nowTime,2);
                String pre01Time = TimeUtil.preDay(nowTime,1);

                Integer rainFall01 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre01Time))) ? 0 : timeMap.get(Long.valueOf(pre01Time)).get(0).getRainFall();
                Integer rainFall02 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre02Time))) ? 0 : timeMap.get(Long.valueOf(pre02Time)).get(0).getRainFall();
                Integer rainFall03 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre03Time))) ? 0 : timeMap.get(Long.valueOf(pre03Time)).get(0).getRainFall();
                Integer rainFall04 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre04Time))) ? 0 : timeMap.get(Long.valueOf(pre04Time)).get(0).getRainFall();
                Integer rainFall05 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre05Time))) ? 0 : timeMap.get(Long.valueOf(pre05Time)).get(0).getRainFall();
                Integer rainFall06 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre06Time))) ? 0 : timeMap.get(Long.valueOf(pre06Time)).get(0).getRainFall();
                Integer rainFall07 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre07Time))) ? 0 : timeMap.get(Long.valueOf(pre07Time)).get(0).getRainFall();
                Integer rainFall08 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre08Time))) ? 0 : timeMap.get(Long.valueOf(pre08Time)).get(0).getRainFall();
                Integer rainFall09 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre09Time))) ? 0 : timeMap.get(Long.valueOf(pre09Time)).get(0).getRainFall();
                Integer rainFall10 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre10Time))) ? 0 : timeMap.get(Long.valueOf(pre10Time)).get(0).getRainFall();
                Integer rainFall11 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre11Time))) ? 0 : timeMap.get(Long.valueOf(pre11Time)).get(0).getRainFall();
                Integer rainFall12 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre12Time))) ? 0 : timeMap.get(Long.valueOf(pre12Time)).get(0).getRainFall();
                Integer rainFall13 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre13Time))) ? 0 : timeMap.get(Long.valueOf(pre13Time)).get(0).getRainFall();
                Integer rainFall14 = org.springframework.util.CollectionUtils.isEmpty(timeMap.get(Long.valueOf(pre14Time))) ? 0 : timeMap.get(Long.valueOf(pre14Time)).get(0).getRainFall();

                //处理20时的数据
                rainDayInfo.setRainFall_2(rainFall01 + rainDayInfo.getRainFall());
                rainDayInfo.setRainFall_3(rainDayInfo.getRainFall_2() + rainFall02);
                rainDayInfo.setRainFall_4(rainDayInfo.getRainFall_3() + rainFall03);
                rainDayInfo.setRainFall_5(rainDayInfo.getRainFall_4()+ rainFall04);
                rainDayInfo.setRainFall_6(rainDayInfo.getRainFall_5() + rainFall05);
                rainDayInfo.setRainFall_7(rainDayInfo.getRainFall_6() + rainFall06);
                rainDayInfo.setRainFall_8(rainDayInfo.getRainFall_7() + rainFall07);
                rainDayInfo.setRainFall_9(rainDayInfo.getRainFall_8() + rainFall08);
                rainDayInfo.setRainFall_10(rainDayInfo.getRainFall_9() + rainFall09);
                rainDayInfo.setRainFall_11(rainDayInfo.getRainFall_10() + rainFall10);
                rainDayInfo.setRainFall_12(rainDayInfo.getRainFall_11() + rainFall11);
                rainDayInfo.setRainFall_13(rainDayInfo.getRainFall_12() + rainFall12);
                rainDayInfo.setRainFall_14(rainDayInfo.getRainFall_13() + rainFall13);
                rainDayInfo.setRainFall_15(rainDayInfo.getRainFall_14() + rainFall14);
                rainDayInfoList.add(rainDayInfo);
            }
        }
        log.info("当前计算得是{}到{}，的20时多日降水，保存到降水基础信息表",startTime,endTime);
        rainDayInfoRepository.saveBatch(rainDayInfoList);
    }


    /**
     * 补全连续降水过程和连续无降水过程
     * @param firstDayOfMonth
     * @param lastDayOfMonth
     * @param stations
     */
    @Override
    public void completionContinueByYear20(String firstDayOfMonth, String lastDayOfMonth, List<String> stations) {
        long ss = System.currentTimeMillis();
        String pre1DayInit = TimeUtil.preDay(firstDayOfMonth,1);
        String nextDayInit = TimeUtil.nextDay(lastDayOfMonth,1);

        //todo 优化 直接查询出来再分组避免频繁查询es
        EsCondition rainDayCondition = EsCondition.getEsCondition();
        rainDayCondition.gte("time",Long.parseLong(pre1DayInit)).lte(Long.parseLong(nextDayInit));
        //2 无降水过程 1 降水过程
        rainDayCondition.gt("rainFall",0).lte(20000).in("stationNo",stations);
        rainDayCondition.size(100000);
        //查询出单站的所有暴雨事件
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
        log.info("查询es用时{}",System.currentTimeMillis() - ss);
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));
        //遍历所有的站点
        stationMap.forEach((stationNo,rainDayInfoList) -> {
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfoList)){
                Collections.sort(rainDayInfoList,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleContinue20(rainDayInfoList, firstDayOfMonth, lastDayOfMonth);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
        });
        log.info("{}到{}单站20连续降水过程保存完成",firstDayOfMonth,lastDayOfMonth);
    }

    /**
     * 新版连续降水20处理
     * @param startTime
     * @param endTime
     */
    @Override
    public void completionContinueByYear20New(String startTime, String endTime) {
        List<Station> stations = StationCache.getStations();
        stations.stream().forEach(x ->{
            //todo 优化 直接查询出来再分组避免频繁查询es
            EsCondition rainDayCondition = EsCondition.getEsCondition();
            rainDayCondition.eq("stationNo",x.getStationNo());
            rainDayCondition.gte("time",Long.parseLong(TimeUtil.preDay(startTime,1))).lte(Long.parseLong(TimeUtil.nextDay(endTime,1)));
            //2 无降水过程 1 降水过程
            rainDayCondition.gt("rainFall",0).lte(20000);
            rainDayCondition.size(100000);
            //查询出单站的所有暴雨事件
            List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfos)){
                Collections.sort(rainDayInfos,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleContinue20(rainDayInfos, startTime, endTime);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
            log.info("当前处理的是{}站点，时间{}到{}单站20连续降水过程保存完成,共处理{}数据",x.getStationNo(),startTime,endTime,rainDayInfos.size());
        });
    }

    @Override
    public void completionNotContinueByYear20(String firstDayOfMonth, String lastDayOfMonth, List<String> stations) {
        long ss = System.currentTimeMillis();
        String pre1DayInit = TimeUtil.preDay(firstDayOfMonth,1);
        String nextDayInit = TimeUtil.nextDay(lastDayOfMonth,1);
        //todo 优化 直接查询出来再分组避免频繁查询es
        EsCondition rainDayCondition = EsCondition.getEsCondition();
        rainDayCondition.gte("time",Long.parseLong(pre1DayInit)).lte(Long.parseLong(nextDayInit));
        //2 无降水过程 1 降水过程
        rainDayCondition.eq("rainFall",0).in("stationNo",stations);
        rainDayCondition.size(100000);
        //查询出单站的所有暴雨事件
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
        log.info("查询es用时{}",System.currentTimeMillis() - ss);
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));
        //遍历所有的站点
        stationMap.forEach((stationNo,rainDayInfoList) -> {
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfoList)){
                Collections.sort(rainDayInfoList,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleNotContinue20(rainDayInfoList, firstDayOfMonth, lastDayOfMonth);
//                rainDayInfoRepository.saveBatch(rainstormInfos1);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
        });
        log.info("{}到{}单站20连续无降水过程保存完成",firstDayOfMonth,lastDayOfMonth);
    }


    /**
     * 新版连续无降水20处理
     * @param startTime
     * @param endTime
     */
    @Override
    public void completionNotContinueByYear20New(String startTime, String endTime) {
        List<Station> stations = StationCache.getStations();
        stations.stream().forEach(x ->{
            //todo 优化 直接查询出来再分组避免频繁查询es
            EsCondition rainDayCondition = EsCondition.getEsCondition();
            rainDayCondition.eq("stationNo",x.getStationNo());
            rainDayCondition.gte("time",Long.parseLong(TimeUtil.preDay(startTime,1))).lte(Long.parseLong(TimeUtil.nextDay(endTime,1)));
            //2 无降水过程 1 降水过程
            rainDayCondition.eq("rainFall",0);
            rainDayCondition.size(100000);
            //查询出单站的所有暴雨事件
            List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfos)){
                Collections.sort(rainDayInfos,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleNotContinue20(rainDayInfos, startTime, endTime);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
            log.info("当前处理的是{}站点，时间{}到{}单站20连续无降水过程保存完成,共处理{}数据",x.getStationNo(),startTime,endTime,rainDayInfos.size());
        });
    }


    @Override
    public void completionContinueByYear08(String firstDayOfMonth, String lastDayOfMonth, List<String> stations) {
        long ss = System.currentTimeMillis();
        String pre1DayInit = TimeUtil.preDay(firstDayOfMonth,1);
        String nextDayInit = TimeUtil.nextDay(lastDayOfMonth,1);
        //todo 优化 直接查询出来再分组避免频繁查询es
        EsCondition rainDayCondition = EsCondition.getEsCondition();
        rainDayCondition.gte("time",Long.parseLong(pre1DayInit)).lte(Long.parseLong(nextDayInit));
        //2 无降水过程 1 降水过程
        rainDayCondition.gt("rainFall08",0).lte(20000).in("stationNo",stations);
        rainDayCondition.size(100000);
        //查询出单站的所有暴雨事件
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
        log.info("查询es用时{}",System.currentTimeMillis() - ss);
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));
        //遍历所有的站点
        stationMap.forEach((stationNo,rainDayInfoList) -> {
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfoList)){
                Collections.sort(rainDayInfoList,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleContinue08(rainDayInfoList, firstDayOfMonth, lastDayOfMonth);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
        });
        log.info("{}到{}单站08连续降水过程保存完成",firstDayOfMonth,lastDayOfMonth);
    }




    /**
     * 新版连续降水08处理
     * @param startTime
     * @param endTime
     */
    @Override
    public void completionContinueByYear08New(String startTime, String endTime) {
        List<Station> stations = StationCache.getStations();
        stations.stream().forEach(x ->{
            //todo 优化 直接查询出来再分组避免频繁查询es
            EsCondition rainDayCondition = EsCondition.getEsCondition();
            rainDayCondition.eq("stationNo",x.getStationNo());
            rainDayCondition.gte("time",Long.parseLong(TimeUtil.preDay(startTime,1))).lte(Long.parseLong(TimeUtil.nextDay(endTime,1)));
            //2 无降水过程 1 降水过程
            rainDayCondition.gt("rainFall08",0).lte(20000);
            rainDayCondition.size(100000);
            //查询出单站的所有暴雨事件
            List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfos)){
                Collections.sort(rainDayInfos,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleContinue08(rainDayInfos, startTime, endTime);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
            log.info("当前处理的是{}站点，时间{}到{}单站08连续降水过程保存完成,共处理{}数据",x.getStationNo(),startTime,endTime,rainDayInfos.size());
        });
    }

    @Override
    public void completionNotContinueByYear08(String firstDayOfMonth, String lastDayOfMonth, List<String> stations) {
        long ss = System.currentTimeMillis();
        String pre1DayInit = TimeUtil.preDay(firstDayOfMonth,1);
        String nextDayInit = TimeUtil.nextDay(lastDayOfMonth,1);
        //todo 优化 直接查询出来再分组避免频繁查询es
        EsCondition rainDayCondition = EsCondition.getEsCondition();
        rainDayCondition.gte("time",Long.parseLong(pre1DayInit)).lte(Long.parseLong(nextDayInit));
        //2 无降水过程 1 降水过程
        rainDayCondition.eq("rainFall08",0).in("stationNo",stations);
        rainDayCondition.size(100000);
        //查询出单站的所有暴雨事件
        List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
        log.info("查询es用时{}",System.currentTimeMillis() - ss);
        Map<String, List<RainDayInfo>> stationMap = rainDayInfos.stream().collect(Collectors.groupingBy(RainDayInfo::getStationNo));
        //遍历所有的站点
        stationMap.forEach((stationNo,rainDayInfoList) -> {
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfoList)){
                Collections.sort(rainDayInfoList,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleNotContinue08(rainDayInfoList, firstDayOfMonth, lastDayOfMonth);
//                rainDayInfoRepository.saveBatch(rainstormInfos1);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
        });
        log.info("{}到{}单站08连续无降水过程保存完成",firstDayOfMonth,lastDayOfMonth);
    }

    /**
     * 新版连续无降水08处理
     * @param startTime
     * @param endTime
     */
    @Override
    public void completionNotContinueByYear08New(String startTime, String endTime) {
        List<Station> stations = StationCache.getStations();
        stations.stream().forEach(x ->{
            //todo 优化 直接查询出来再分组避免频繁查询es
            EsCondition rainDayCondition = EsCondition.getEsCondition();
            rainDayCondition.eq("stationNo",x.getStationNo());
            rainDayCondition.gte("time",Long.parseLong(TimeUtil.preDay(startTime,1))).lte(Long.parseLong(TimeUtil.nextDay(endTime,1)));
            //2 无降水过程 1 降水过程
            rainDayCondition.eq("rainFall08",0);
            //查询出单站的所有暴雨事件
            List<RainDayInfo> rainDayInfos = rainDayInfoRepository.selectList(rainDayCondition);
            if (!org.springframework.util.CollectionUtils.isEmpty(rainDayInfos)){
                Collections.sort(rainDayInfos,(a, b) ->{
                    return (int)(a.getTime() - b.getTime());
                });
                List<RainDayInfo> rainstormInfos1 = new ArrayList<>();
                rainstormInfos1 = transSingleNotContinue08(rainDayInfos, startTime, endTime);
                if (!org.springframework.util.CollectionUtils.isEmpty(rainstormInfos1)){
                    rainDayInfoRepository.saveBatchNotNull(rainstormInfos1);
                }
            }
            log.info("当前处理的是{}站点，时间{}到{}单站08连续降水过程保存完成,共处理{}数据",x.getStationNo(),startTime,endTime,rainDayInfos.size());
        });
    }

    /**
     * 查询每年的有效站点数
     * @return
     */
    @Override
    public Map<String, Integer> queryYearValidStNum(String riverName) {
        EsCondition stationCondition = EsCondition.getEsCondition();
        if (Objects.nonNull(riverName)){
            stationCondition.eq("river",riverName);
        }
        List<Station> stationList = stationInfoRepository.selectList(stationCondition);
        List<String> stationNoList = RectField.getBeanFields(stationList, "stationNo");


        EsAggCondition esAggCondition = EsAggCondition.getInstance();
        Group yearGroup = esAggCondition.Group("year");
        yearGroup.size(1000);
        Group stationNoGroup = yearGroup.groupSub("stationNo");
        stationNoGroup.size(10000);
        EsCondition extremeCondition = esAggCondition.getCondition();
        extremeCondition.in("stationNo", com.hxgis.common.utils.CollectionUtils.convertCollectionString(stationNoList));

        List<RainInfoAnalysDTO> rainInfoAnalysDTOS = rainDayInfoRepository.selectListAgg(esAggCondition, new DataWrapper<RainInfoAnalysDTO>() {
            @Override
            public RainInfoAnalysDTO wrapper(Map<String, Object> data) {
                RainInfoAnalysDTO rainInfoAnalysDTO = new RainInfoAnalysDTO();
                rainInfoAnalysDTO.setStationNo(data.get("stationNo").toString());
                rainInfoAnalysDTO.setYear(data.get("year").toString());
                return rainInfoAnalysDTO;
            }
        });
        Map<String, List<RainInfoAnalysDTO>> collect = rainInfoAnalysDTOS.stream().collect(Collectors.groupingBy(RainInfoAnalysDTO::getYear));
        Map<String, Integer> yearStationMap = new HashMap<>();
        collect.forEach((year,stations) -> {
            Set<String> stationNums = stations.stream().map(RainInfoAnalysDTO::getStationNo).collect(Collectors.toSet());
            yearStationMap.put(year,stationNums.size());
        });

        return yearStationMap;
    }


    private List<RainDayInfo> transSingleContinue20(List<RainDayInfo> rainDayInfos, String firstDayOfMonth, String lastDayOfMonth) {
        List<RainDayInfo> rainstormInfoNew = new ArrayList<>();
        Map<Long, RainDayInfo> rainDayInfoMap = rainDayInfos.stream().collect(Collectors.toMap(RainDayInfo::getTime, value -> value));
        /**
         * 1.只查第一条的前一天数据
         * 2.查询最后一条的后一天数据
         */
        //todo 循环时间
        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(firstDayOfMonth,1), TimeUtil.nextDay(lastDayOfMonth,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //循环所有的时间日期
        for (String nowTime : monthBetweenDateStr) {
            RainDayInfo rainDayInfo = rainDayInfoMap.get(Long.parseLong(nowTime));
            if (Objects.isNull(rainDayInfo) ){
                continue;
            }
            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getContinueRainFll() == null){
                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
                if (Objects.nonNull(RainDayInfo1)){
                    rainDayInfo.setContinueRainFll(rainDayInfo.getStationNo() + rainDayInfo.getTime());
                }else{
                    rainDayInfo.setContinueRainFll(null);
                }
            }else{
                rainDayInfo.setContinueRainFll(rainDayInfo_pre.getContinueRainFll());
            }
            RainDayInfo rainDayInfoNew = new RainDayInfo();
            rainDayInfoNew.setId(rainDayInfo.getId());
            rainDayInfoNew.setContinueRainFll(rainDayInfo.getContinueRainFll());
            rainstormInfoNew.add(rainDayInfoNew);
        }



//        for (int i = 0; i < rainDayInfos.size(); i++) {
//            RainDayInfo rainDayInfo = rainDayInfos.get(i);
//            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
//            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getContinueRainFll() == null){
//                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
//                if (Objects.nonNull(RainDayInfo1)){
//                    rainDayInfo.setContinueRainFll(rainDayInfo.getStationNo() + rainDayInfo.getTime());
//                }else{
//                    rainDayInfo.setContinueRainFll(null);
//                }
//            }else{
//                rainDayInfo.setContinueRainFll(rainDayInfo_pre.getContinueRainFll());
//            }
//        }
//        rainDayInfos.stream().forEach(x -> {
//            RainDayInfo rainDayInfo = new RainDayInfo();
//            rainDayInfo.setId(x.getId());
//            rainDayInfo.setContinueRainFll(x.getContinueRainFll());
//            rainstormInfoNew.add(rainDayInfo);
//        });
//        rainstormInfoNew.addAll(rainDayInfos);
        return rainstormInfoNew;
    }

    private List<RainDayInfo> transSingleContinue08(List<RainDayInfo> rainDayInfos, String firstDayOfMonth, String lastDayOfMonth) {
        List<RainDayInfo> rainstormInfoNew = new ArrayList<>();
        Map<Long, RainDayInfo> rainDayInfoMap = rainDayInfos.stream().collect(Collectors.toMap(RainDayInfo::getTime, value -> value));
        /**
         * 1.只查第一条的前一天数据
         * 2.查询最后一条的后一天数据
         */


        //todo 循环时间
        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(firstDayOfMonth,1), TimeUtil.nextDay(lastDayOfMonth,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //循环所有的时间日期
        for (String nowTime : monthBetweenDateStr) {
            RainDayInfo rainDayInfo = rainDayInfoMap.get(Long.parseLong(nowTime));
            if (Objects.isNull(rainDayInfo) ){
                continue;
            }
            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getContinueRainFll08() == null){
                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
                if (Objects.nonNull(RainDayInfo1)){
                    rainDayInfo.setContinueRainFll08(rainDayInfo.getStationNo() + rainDayInfo.getTime());
                }else{
                    rainDayInfo.setContinueRainFll08(null);
                }
            }else{
                rainDayInfo.setContinueRainFll08(rainDayInfo_pre.getContinueRainFll08());
            }
            RainDayInfo rainDayInfoNew = new RainDayInfo();
            rainDayInfoNew.setId(rainDayInfo.getId());
            rainDayInfoNew.setContinueRainFll08(rainDayInfo.getContinueRainFll08());
            rainstormInfoNew.add(rainDayInfoNew);
        }


//        for (int i = 0; i < rainDayInfos.size(); i++) {
//            RainDayInfo rainDayInfo = rainDayInfos.get(i);
//            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
//            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getContinueRainFll08() == null){
//                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
//                if (Objects.nonNull(RainDayInfo1)){
//                    rainDayInfo.setContinueRainFll08(rainDayInfo.getStationNo() + rainDayInfo.getTime());
//                }else{
//                    rainDayInfo.setContinueRainFll08(null);
//                }
//            }else{
//                rainDayInfo.setContinueRainFll08(rainDayInfo_pre.getContinueRainFll08());
//            }
//        }
//        rainDayInfos.stream().forEach(x -> {
//            RainDayInfo rainDayInfo = new RainDayInfo();
//            rainDayInfo.setId(x.getId());
//            rainDayInfo.setContinueRainFll08(x.getContinueRainFll08());
//            rainstormInfoNew.add(rainDayInfo);
//        });
//        rainstormInfoNew.addAll(rainDayInfos);
        return rainstormInfoNew;
    }

    private List<RainDayInfo> transSingleNotContinue08(List<RainDayInfo> rainDayInfos, String firstDayOfMonth, String lastDayOfMonth){
        List<RainDayInfo> rainstormInfoNew = new ArrayList<>();
        Map<Long, RainDayInfo> rainDayInfoMap = rainDayInfos.stream().collect(Collectors.toMap(RainDayInfo::getTime, value -> value));
        /**
         * 1.只查第一条的前一天数据
         * 2.查询最后一条的后一天数据
         */


        //todo 循环时间
        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(firstDayOfMonth,1), TimeUtil.nextDay(lastDayOfMonth,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //循环所有的时间日期
        for (String nowTime : monthBetweenDateStr) {
            RainDayInfo rainDayInfo = rainDayInfoMap.get(Long.parseLong(nowTime));
            if (Objects.isNull(rainDayInfo) ){
                continue;
            }
            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getNotContinueRainFll08() == null){
                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
                if (Objects.nonNull(RainDayInfo1)){
                    rainDayInfo.setNotContinueRainFll08(rainDayInfo.getStationNo() + rainDayInfo.getTime());
                }else{
                    rainDayInfo.setNotContinueRainFll08(null);
                }
            }else{
                rainDayInfo.setNotContinueRainFll08(rainDayInfo_pre.getNotContinueRainFll08());
            }
            RainDayInfo rainDayInfoNew = new RainDayInfo();
            rainDayInfoNew.setId(rainDayInfo.getId());
            rainDayInfoNew.setNotContinueRainFll08(rainDayInfo.getNotContinueRainFll08());
            rainstormInfoNew.add(rainDayInfoNew);
        }


//        for (int i = 0; i < rainDayInfos.size(); i++) {
//            RainDayInfo rainDayInfo = rainDayInfos.get(i);
//            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
//            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getNotContinueRainFll08() == null){
//                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
//                if (Objects.nonNull(RainDayInfo1)){
//                    rainDayInfo.setNotContinueRainFll08(rainDayInfo.getStationNo() + rainDayInfo.getTime());
//                }else{
//                    rainDayInfo.setNotContinueRainFll08(null);
//                }
//            }else{
//                rainDayInfo.setNotContinueRainFll08(rainDayInfo_pre.getNotContinueRainFll08());
//            }
//        }
//        rainDayInfos.stream().forEach(x -> {
//            RainDayInfo rainDayInfo = new RainDayInfo();
//            rainDayInfo.setId(x.getId());
//            rainDayInfo.setNotContinueRainFll08(x.getNotContinueRainFll08());
//            rainstormInfoNew.add(rainDayInfo);
//        });
//        rainstormInfoNew.addAll(rainDayInfos);
        return rainstormInfoNew;
    }

    private List<RainDayInfo> transSingleNotContinue20(List<RainDayInfo> rainDayInfos, String firstDayOfMonth, String lastDayOfMonth) {
        List<RainDayInfo> rainstormInfoNew = new ArrayList<>();
        Map<Long, RainDayInfo> rainDayInfoMap = rainDayInfos.stream().collect(Collectors.toMap(RainDayInfo::getTime, value -> value));
        /**
         * 1.只查第一条的前一天数据
         * 2.查询最后一条的后一天数据
         */

        //todo 循环时间
        List<String> monthBetweenDateStr = null;
        try {
            monthBetweenDateStr = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay(firstDayOfMonth,1), TimeUtil.nextDay(lastDayOfMonth,1));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //循环所有的时间日期
        for (String nowTime : monthBetweenDateStr) {
            RainDayInfo rainDayInfo = rainDayInfoMap.get(Long.parseLong(nowTime));
            if (Objects.isNull(rainDayInfo) ){
                continue;
            }
            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getNotContinueRainFll() == null){
                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
                if (Objects.nonNull(RainDayInfo1)){
                    rainDayInfo.setNotContinueRainFll(rainDayInfo.getStationNo() + rainDayInfo.getTime());
                }else{
                    rainDayInfo.setNotContinueRainFll(null);
                }
            }else{
                rainDayInfo.setNotContinueRainFll(rainDayInfo_pre.getNotContinueRainFll());
            }
            RainDayInfo rainDayInfoNew = new RainDayInfo();
            rainDayInfoNew.setId(rainDayInfo.getId());
            rainDayInfoNew.setNotContinueRainFll(rainDayInfo.getNotContinueRainFll());
            rainstormInfoNew.add(rainDayInfoNew);
        }



//        for (int i = 0; i < rainDayInfos.size(); i++) {
//            RainDayInfo rainDayInfo = rainDayInfos.get(i);
//            String preDay = TimeUtil.preDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            String nextDay1 = TimeUtil.nextDay(rainDayInfo.getTime().toString(), 1, TimeUtil.FORMATOR_YMD);
//            RainDayInfo rainDayInfo_pre = rainDayInfoMap.get(Long.parseLong(preDay));
//            if (Objects.isNull(rainDayInfo_pre) || rainDayInfo_pre.getNotContinueRainFll() == null){
//                RainDayInfo RainDayInfo1 = rainDayInfoMap.get(Long.valueOf(nextDay1));
//                if (Objects.nonNull(RainDayInfo1)){
//                    rainDayInfo.setNotContinueRainFll(rainDayInfo.getStationNo() + rainDayInfo.getTime());
//                }else{
//                    rainDayInfo.setNotContinueRainFll(null);
//                }
//            }else{
//                rainDayInfo.setNotContinueRainFll(rainDayInfo_pre.getNotContinueRainFll());
//            }
//
//        }
//        rainDayInfos.stream().forEach(x -> {
//            RainDayInfo rainDayInfo = new RainDayInfo();
//            rainDayInfo.setId(x.getId());
//            rainDayInfo.setNotContinueRainFll(x.getNotContinueRainFll());
//            rainstormInfoNew.add(rainDayInfo);
//        });
//        rainstormInfoNew.addAll(rainDayInfos);
        return rainstormInfoNew;
    }


    private List<RainDayInfo>  deviceToRainDay(String startTime, String endTime, List<String> sids) {

        List<Map> initLists = Collections.EMPTY_LIST;
        //拆分站点
//        List<String>[] lists = CollectionUtils.subArrays(sids, 800);
//        for (int i = 0; i < lists.length; i++) {
//            params.put("staIds", lists[i].toString());
//            List<Map> getSurfEleByTimeRangeAndStaID = cimissClient.getJsonData(dataFormat, "getSurfEleByTimeAndStaID", params, Map.class);
//            if (!org.springframework.util.CollectionUtils.isEmpty(getSurfEleByTimeRangeAndStaID)) {
//                if (org.springframework.util.CollectionUtils.isEmpty(initLists)) {
//                    initLists = getSurfEleByTimeRangeAndStaID;
//                } else {
//                    initLists.addAll(getSurfEleByTimeRangeAndStaID);
//                }
//            }
//        }

        //优化后 还可以根据时间去拆分
        List<Map> getSurfEleByTimeRangeAndStaID = surfChnMulDayMapper.getDataByTimeAndstationNoListThreads(startTime, endTime, sids);
        if (!org.springframework.util.CollectionUtils.isEmpty(getSurfEleByTimeRangeAndStaID)) {
            if (org.springframework.util.CollectionUtils.isEmpty(initLists)) {
                initLists = getSurfEleByTimeRangeAndStaID;
            } else {
                initLists.addAll(getSurfEleByTimeRangeAndStaID);
            }
        }

        List<RainDayInfo> rainDayInfos = new ArrayList<>();
        if (!org.springframework.util.CollectionUtils.isEmpty(initLists)){
            initLists.stream().forEach(x -> {
                RainDayInfo rainDayInfo = new RainDayInfo();
                rainDayInfo.setStationNo(x.get("Station_Id_C").toString());
                //20-20才能算是当日降水
                rainDayInfo.setRainFall(new BigDecimal(x.get("PRE_Time_2020").toString()).multiply(new BigDecimal(10)).intValue());
                rainDayInfo.setRainFall08(new BigDecimal(x.get("PRE_Time_0808").toString()).multiply(new BigDecimal(10)).intValue());
                String datetime = TimeUtil.changeStyle(x.get("Datetime").toString(), TimeUtil.WEB_FORMATOR_YMDHMS, TimeUtil.FORMATOR_YMD);
                rainDayInfo.setTime(Integer.parseInt(datetime));
                rainDayInfo.setYear(datetime.substring(0,4));
                rainDayInfo.setDays(datetime.substring(4,8));
                rainDayInfo.setId(x.get("Station_Id_C").toString() + Long.parseLong(datetime));
                rainDayInfos.add(rainDayInfo);
            });
        }
        return rainDayInfos;
    }
}
